<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%  
    String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title>用户列表</title>
<script src="resources/js/jquery-1.8.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	pageScrollBar();
});
 function pageScrollBar(){
	 var pageStr="";          //拼接输出html文本
	 var startPoint = 1;      //页码起始位置 
     var endPoint = 5;       //页面结束位置
	 var pageNo=Number($("#hidden_pageNo").val()); //页码
	 var totalPage=Number($("#hidden_totalPage").val()); //总页数
	 
     //标记开始位置和结束位置
     if (pageNo > 2) {
         startPoint = pageNo - 2;
         endPoint = pageNo + 2;
     }
     //控制开始位置上限
     if( startPoint>totalPage){
     	startPoint =totalPage;
      }
      //控制结束位置上限
     if (endPoint >totalPage) {
         endPoint = totalPage;
     }
    
     //循环显示页码条
     for(var i=startPoint;i<=endPoint;i++){
    	  if(pageNo==i){
    		  pageStr+="<span style='color:red;'>"+i+"</span></a>";
    	   }else{
    		  pageStr+="<a class='' href='javascript:void(0);' onclick='pageUtil("+i+")'>"+i+"</a>";
    	   }
	     }
    $("#page_scroll_bar").html(pageStr);
 }
 
 function pageUtil(pageNo){
	 window.location.href="user/list?pageNo="+pageNo;
 };
</script>
</head>
<body>
<form action="user/list" method="post">
    <table>
     <tr>
       <td>编号ID：<input name="id"  type="text" value="${page.params.id}"/></td>
       <td>用户名称：<input name="userName" type="text" value="${page.params.userName}"/></td>
       <td> <input type="submit" value="查询" /></td>
     </tr>
    </table>
 </form>
  	<table border="1">
			<tr>
			 <td colspan="10"  style="text-align: center;">
				 <span>用户列表</span>
			 </td>
			</tr>
			<tr>
			    <th>编号ID</th>
				<th>用户ID</th>
				<th>用户名称</th>
				<th>年龄</th>
				<th>头像地址</th>
				<th>身份证号</th>
			    <th>联系方式</th>
				<th>性别</th>
				<th>创建时间</th>
				<th>操作</th>
			</tr>
			 <c:choose>
                <c:when test="${!empty page.results}">
                  <c:forEach var="pr" items="${page.results}">
                    <tr>
					  <td>${pr.id}</td>
					  <td>${pr.userId}</td>
					  <td>${pr.userName}</td>
					  <td>${pr.age}</td>
					  <td>${pr.avatar}</td>
					  <td>${pr.identity}</td>
					  <td>${pr.mobile}</td>
					  <td>${pr.sex}</td>
					  <td>${pr.createTime}</td>
					  <td><input  type="button" value="删除"/></td>
				     </tr>
                  </c:forEach>
                </c:when>
                <c:otherwise>
                     <tr><td colspan="10"><span style="color: red;">没有查到记录！</span></td></tr>
                </c:otherwise>
             </c:choose>
		</table>
		<table>
			<tr>
			   <td>
				    <c:choose>
					   <c:when test="${page.pageNo==1}">
					                   首页 上一页
					   </c:when>
					   <c:otherwise>
					    	<a class="home_page" href="javascript:void(0);" onclick="pageUtil(1)">首页</a>
				 	        <a class="back_page" href="javascript:void(0);" onclick="pageUtil('${page.pageNo-1}')">上一页</a>
					   </c:otherwise>
				    </c:choose>
					<span id="page_scroll_bar"></span>
					<c:choose>
					   <c:when test="${page.pageNo!=page.totalPage}">
					     	<a  class="next_page"  href="javascript:void(0);" onclick="pageUtil('${page.pageNo+1}')">下页</a>
				 	        <a  class="last_page"  href="javascript:void(0);" onclick="pageUtil('${page.totalPage}')">末页</a> 
					   </c:when>
					   <c:otherwise>
					    	下页   末页   
					   </c:otherwise>
					</c:choose>
				    <input id="hidden_pageNo" type="hidden"  value="${page.pageNo}" />
				    <input id="hidden_totalPage" type="hidden" value="${page.totalPage}" />
				 </td>
			</tr>
		</table>
</body>
</html>